home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 43 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.5 KB

  1. Path: news.iconn.net!news
  2. From: thecrow@iconn.net (The Crow)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Arrays-What are they good for?
  5. Date: 2 Jan 1996 02:46:03 GMT
  6. Organization: I rule the world
  7. Message-ID: <4ca69b$1o1@news.iconn.net>
  8. References: <4c6fc5$jv3$1@mhadf.production.compuserve.com>
  9. NNTP-Posting-Host: st-ts00-02.iconn.net
  10. Mime-Version: 1.0
  11. Content-Type: Text/Plain; charset=US-ASCII
  12. X-Newsreader: WinVN 0.99.6
  13.  
  14. In article <4c6fc5$jv3$1@mhadf.production.compuserve.com>, 
  15. 71702.1123@CompuServe.COM says...
  16. >
  17. >
  18. >Hello all....
  19. >
  20. >What are arrays?  After reading about them countless times I cannot understand
  21. >their purpose nor how to use them.  Can someone give me an example showing how
  22. >they can be used?  Thank you..
  23. >Merlin
  24.  
  25. Say you want to read 16384 bytes of a file into memory, then manipulate it a 
  26. little bit. Rather than have 16384 different variable that you could never keep 
  27. track of, you just
  28.  
  29. int FBlock[16383];
  30.  
  31. and you can read all the bytes of the file into memory with a simple loop
  32.  
  33. For(i=0;i<16384;i++)
  34. {
  35. read in the byte here
  36. }
  37. and all the bytes will be stored in one variable, nice an neat, and you can 
  38. access any one of those bytes quickly. Say you want the 10th one, just say
  39.  
  40. a = FBlock[9];    // it starts with 0 so 9 is the 10th
  41.  
  42. you dont HAVE to use variable, but the only alternative is having 100 pages of 
  43. code and 1000's of different variable names which just isnt anyones idea of a 
  44. good time.
  45.  
  46.  
  47. -- 
  48. The Crow - thecrow@iconn.net
  49. "It can't rain all the time"
  50. -Kryptology
  51.  
  52.